#!/usr/bin/ruby


require "yaml"
require "rubygems"
require "mongo"
require "pp"

$LOAD_PATH << File.dirname($0) + "/../lib"
require 'mongolock/mutex'
$VERBOSE=true
$DEBUG=true

raise "No configuration specified" if ARGV[0].nil?
conf = YAML::load_file ARGV[0]

cnx = Mongo::Connection.new
db = cnx.db conf["database"]

mutex = MongoLock::Mutex.new db, "m1"
puts "Trying to acquire mutex..."

begin
	mutex.acquire
	puts "Mutex acquired! Sleeping now..."
	sleep 100

rescue Interrupt
	puts "--interrupt--"
	# 
ensure
	mutex.release
	puts "Mutex released"
end

#auth = db.authenticate conf["username"], conf["password"]
#raise RuntimeError, "bad login or password" unless auth
#collection = db.collection DB_COLLECTION
# request mutex

